mac中的PHP连接问题

时间:2016-01-01 10:31:04

标签: php macos mamp

我在mac os上使用 MAMP 这是进行数据库连接时的错误

致命错误:未捕获错误:在/Applications/MAMP/htdocs/databases.php:3中调用未定义的函数mysql_connect()堆栈跟踪:/Applications/MAMP/htdocs/databases.php中引发的#0 {main}第3行

使用的代码

<?php 

$connection = mysql_connect("localhost","root","");

if(!$connection)
{

    die("Database connection failed" . mysql_error());
}
?>

3 个答案:

答案 0 :(得分:4)

只是改变 从

$connection = mysql_connect("localhost","root","");

$connection = mysqli_connect("localhost","root","");

注意mysqli中的'i'

答案 1 :(得分:2)

如果您碰巧使用PHP 7,那么现在是时候学习新内容了,因为mysql_*函数已经被弃用了一段时间,现在已从PHP 7移除{[indent=4] uses Gtk class TestWindow : Window notebook:Gtk.Notebook init // General characteristics of the window title = "Gtk Containers" default_height = 250 default_width = 250 window_position = WindowPosition.CENTER destroy.connect(Gtk.main_quit) // Now building the notebook var notebook = new Gtk.Notebook() var label1 = new Gtk.Label("Page one") var label2 = new Gtk.Label("Page two") var label3 = new Gtk.Label("Page three") var label4 = new Gtk.Label("Page four") var child1 = new Button.with_label ("Go to next page") child1.clicked += def () notebook.set_current_page(2) var child2 = new Button.with_label ("Go to next page") child2.clicked += def () notebook.set_current_page(3) var child3 = new Button.with_label ("Go to next page") child3.clicked += def () notebook.set_current_page(4) var child4 = new Button.with_label ("Go to first page") child4.clicked += def () notebook.set_current_page(1) notebook.append_page(child1, label1) notebook.append_page(child2, label2) notebook.append_page(child3, label3) notebook.append_page(child4, label4) // Now building the grid var grid = new Grid() var button1 = new Gtk.Button.with_mnemonic("Button_1") var button2 = new Button.with_mnemonic("Button 2") // Attaching all elements into the grid grid.attach(notebook, 0,0,2,1) grid.attach(button1, 0,1,1,1) grid.attach(button2, 1,1,1,1) add(grid) init Gtk.init (ref args) var test = new TestWindow () test.show_all () Gtk.main () 3}}

如果您不确定自己使用的是哪个版本,可以致电seen in this RFC.,这将显示您当前的PHP版本。

备选方案:

答案 2 :(得分:0)

试试此代码

<?php  

   $database = mysql_connect("hostname","username","password");
   mysql_select_db("databasename",$database);

?>