Newbie php-mySQL setup prob

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Olwe
Forum Newbie
Posts: 6
Joined: Tue Aug 22, 2006 11:08 pm

Newbie php-mySQL setup prob

Post by Olwe »

Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I'm not seeing how to let php know about my mySQL database. I've just set up php5 and mySQL 5 on WinXP, but the phpinfo() test has no mySQL section and a quick test:

Code: Select all

<?php 
$user="me";
$password="secretbwah";
$database="scstore";
mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="CREATE TABLE contacts (id int(6) NOT NULL auto_increment,first varchar(15) NOT NULL,last varchar(15) NOT NULL,phone varchar(20) NOT NULL,mobile varchar(20) NOT NULL,fax varchar(20) NOT NULL,email varchar(30) NOT NULL,web varchar(30) NOT NULL,PRIMARY KEY (id),UNIQUE id (id),KEY id_2 (id))";
mysql_query($query);
mysql_close();
?>
produces:

Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Group\Apache2\htdocs\phpstuff\test1.php on line 12

I know I'm missing something very basic here....


Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Probably yes ;)

http://de2.php.net/mysql might help.
Installation on Windows Systems...
PHP 5+
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

PHP 5 does not load the mysql extension automatically. It loads the mysqli extension instead. You can do one of two things. Either enable the mysql extension in your php.ini file (search these boards for how to do it, it has been described several times before here) or use the mysqli_* family of functions instead of mysql_* functions. I prefer the mysqli_* functions because of their OOP nature, but you can still go with a procedural coding system using them if you prefer. If your app is built with the mysql_* functions, you have no choice but to enable the extensions unless you want to recode the app.
Olwe
Forum Newbie
Posts: 6
Joined: Tue Aug 22, 2006 11:08 pm

Post by Olwe »

Something's still amiss. I've got the extension uncommented in php.ini, the php_mysql.dll in a PATH-visible place. PHP and Apache2.0 are working, mySQL is working. Again, what am I missing here? I assume the phpinfo() test should contain a section on mySQL and that the test I posted (badly) should have run....
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Did you change the appropriate php.ini? phpinfo() tells you which file is used.
Did you restart the apache process after changing that file?
Did you get an error because libmysql.dll wasn't found?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Do you have the right MySQL Client API? Can you run phpMyAdmin?
Olwe
Forum Newbie
Posts: 6
Joined: Tue Aug 22, 2006 11:08 pm

Post by Olwe »

Det jeht doch nischt!

Everything I've read tells me NOT to put stuff in the C:\WINDOWS directory, but apparently (according the the phpinfo() output) it was expecting to see php.ini in C:\WINDOWS--and when I put it there, viola! it works. I'm using the php_mysqli.dll, but what exactly does it do more than php_mysql.dll?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

phpinfo() displays the last location php was looking for a ini file.
C.\windows is the very last location on a win32 system + no php.ini -> c:\windows on phpinfo()
see http://de2.php.net/ini
crispgm
Forum Newbie
Posts: 1
Joined: Fri Aug 25, 2006 4:49 am

i have this problem, too

Post by crispgm »

and i did as http://de2.php.net/mysql
but it doesn‘t work
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Olwe wrote:Det jeht doch nischt!

Everything I've read tells me NOT to put stuff in the C:\WINDOWS directory, but apparently (according the the phpinfo() output) it was expecting to see php.ini in C:\WINDOWS--and when I put it there, viola! it works. I'm using the php_mysqli.dll, but what exactly does it do more than php_mysql.dll?
msqli functions are object oriented functions. They are still undocumented in the PHP manual. mysql functions are what PHP4 used (and are still usable by PHP5) but are not object oriented at all.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Everah wrote:They are still undocumented in the PHP manual.
uh? 8O
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Sorry, that was retarded of me. Versioning is not documented in the manual. My mistake. Please disregard that last, doofus level comment.
Post Reply