PHP中mysql_fetch_array()和mysql_fetch_row()的区别
最近在做PHP与数据库交互的project,急于求成,模仿了下例子就开始动手,结果误把mysql_fetch_array写成了mysql_fetch_row,囧事来了,发现返回的数组居然是index=>value的形式,而明明记得是field name=>value的哈,查手册才明白。
1. mysql_fetch_array的函数原型是
array mysql_fetch_array ( resource $result [, int $result_type= MYSQL_BOTH ] )
Returns an array that corresponds to the fetched row and moves the internal data pointer ahead.
The type of returned array depends on how result_type is defined. By using MYSQL_BOTH (default), you'll get an array with both associative and number indices. Using MYSQL_ASSOC, you only get associative indices (as mysql_fetch_assoc() works), using MYSQL_NUM, you only get number indices (as mysql_fetch_row() works).
2. 这就很明白了,若设定不同的参数,mysql_fetch_array()可以做到mysql_fetch_row()和mysql_fetch_assoc()的功能,而后两个函数就只接受第一个参数,返回的分别是associative=>value, index=>value的数组
3.MYSQL_BOTH是什么效果呢,测试了下
Sql: select firstname,lastname from table where id="c01";
$array=mysql_fetch_array($result,MYSQL_BOTH);
$array[0]和$array['firstname']一样
相关文档:
对于针对字符串位置的操作,第一个位置被标记为1。
ASCII(str) 返回字符串str的最左面字符的ASCII代码值。如果str是空字符串,返回0。如果str是NULL,返回NULL。
mysql> select ASCII('2');
-> 50
mysql> select ASCII(2);
-> 50
mysql> select ASCII('dx');
-> 100
也 ......
1. 使用GRANT语句添加:首先在数据库本机上用ROOT用户
登录MySql(我是用远程控制linux服务器,相当于在服务器本机登录MySql了),然后输入:
mysql>GRANT ALL PRIVILEGES ON *.* TO admin@localhost IDENTIFIED BY 'something' WITH GRANT OPTION;
添加一个用户admin并授权通过本地机(localhost)访问,密码“s ......
<?
$_mysqlhost="localhost";
$_mysqluser="root";
$_mysqlpass="";
$_mysqldata="mydata";
$_connect=mysql_connect($_mysqlhost,$_mysqluser,$_mysqlpass) or die ("错误".mysql_error());
mysql_query("SET character_set_connection=utf8, character_set_results=utf8, character_set_client=binary", $ ......
在以前的做的例子中遇到过重复的加载的错误 额 那个是通过include_once()来解决 或者不让他重复加载把重复的include()去掉一个或多个,最终只剩下一个这样问题就解决了,但今天遇到的问题就棘手了 说是找不到文件。
事情是这样的 ,今天在文件夹里再新建了一个文件夹,然后以前includ ......
这段时间被这个困扰了很久,通过修改配置文件,终于把这个问题解决了。
自己在网上也找了很多关于解决这个问题的方法,但是都讲的不太清楚,所以今天在这重新说下这个问题。
我的解决方法是通过修改mysql的配置文件my.ini,方法如下:
在my.ini中可以发现有这么一段代码:
[client]
port=3306
[mysql]
default ......