php连接到sql本地服务器

时间:2015-12-02 00:20:07

标签: php mysql

我正在尝试连接到mysql本地服务器,但是当我选择first_try_books数据库时,mysql_select_db函数返回false。

      <?php
 $conn=mysql_connect();
 if($conn) print("Connect Successfully");
 else {echo "error in connection ... try again "; die();}
if( mysql_select_db("first_try_books",$conn))
    print("select Successfully");
else
    print("error select");  
if( $tab=mysql_query("SELECT book_id FROM lib",$conn))
    print("query Successfully");

      ?><!-- end PHP script -->

this is the database

1 个答案:

答案 0 :(得分:0)

如何使用其他驱动程序连接到BD?

您可以使用PDO

$SQL= new PDO('mysql:host=localhost;dbname=data_base','user','pass');

或mysqli

$SQL= new mysqli('localhost','user','pass','data_base');