1
我使用的是Ubuntu 12.10,並且我安裝了LAMP。當我學習PHP時,我遇到了連接mysql和php的話題。這是我學習的代碼LAMP中的php和mysql連接
<?php
$db = mysql_connect('localhost','root','dbpass') or die('Unable to connect. Check your connection ');
$query = 'CREATE DATABASE IF NOT EXISTS moviesite';
mysql_query($query,$db) or die(mysql_error($db));
mysql_select_db('moviesite',$db) or die(mysql_error($db));
$query2 = 'CREATE TABLE movie (movie_id integer not null, moviename varchar(255) not null, movierating integer not null)';
mysql_query($query,$db) or die(mysql_error($db));
echo "movie database succecfully created ";
?>
當我在我的Windows環境(我有雙引導窗口和Ubuntu)嘗試這個,它工作正常。在Windows中我正在使用eastPHP。但在Ubuntu中,它不顯示任何東西。我試圖找到語法錯誤,但它與書中給出的一樣。那麼問題是什麼?
它說:「[Tue Oct 23 13:50:15 2012] [error] [client 127.0.0.1] PHP致命錯誤:調用未定義的函數mysql_connect()在/var/www/dbcon2.php在線8「但是我的功能不正確嗎? – user1263375
在這種情況下,您可能需要安裝mysql擴展。試試'sudo apt-get install php5-mysql' – troelskn