Home  >  Article  >  Backend Development  >  新手求教数据库连接的有关问题

新手求教数据库连接的有关问题

WBOY
WBOYOriginal
2016-06-13 12:04:48681browse

新手求教数据库连接的问题
 $a=mysql_connect("127.0.0.1","root","123456");
 mysql_select_db("myweb",$a);
 mysql_query("set character set 'utf8'");
$sql="select * from `test` limit 1";
$query=mysql_query($sql,$a);
$data=mysql_fetch_array($query);
var_dump($data);
echo 111;
?>
直接用浏览器打开没问题,为什么用cmd php 打开会报错呢

------解决方案--------------------
cli和web用的是不同的php.ini
cli 模式的php.ini裏面沒有開啓php mysql 擴展。

找到cli下使用的php.ini,然後extension=php_mysql.dll 把前面;去掉,重啓服務就可以了。

要找出cli下使用哪個php.ini
可以
phpinfo();
?>
保存為phpinfo.php
然後運行
php phpinfo.php 
在輸出中找到Loaded_Configuration File => 'xxxx'

xxxx就是使用的php.ini 路徑。


------解决方案--------------------
php --ini

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn