Strahan Posted October 2, 2008 Share Posted October 2, 2008 PHP version: 5.2.6 MySQL version: 5 ---------------------- I'm just learning php and decided to try to make my own version of a tinyurl.com like service. I have a form that collects the url to link to and the name to use for the shortened url then tries to write to a database. This is the code: echo "Creating new URL ...<BR><BR>"; $query = "INSERT INTO URLs (owner, sourceurl, tagname) VALUES (1, '" . $_REQUEST["sourceurl"] . "', '" . $_REQUEST["newtag"] . "')"; $db = mysql_connect(localhost,"username","password"); mysql_select_db("urls") or die( "Unable to select database"); $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); echo "New record inserted with ID ".mysql_insert_id(); mysql_free_result($result); mysql_close($db); When I run it, I get: Fatal error: Call to undefined function mysql_connect() in D:\sites\url\index.php on line 22 Now I did see the post here talking about how to fix it. I followed all the steps... I set the following things in my d:\apps\php\php.ini: extension_dir = "d:\apps\php" extension=php_mysqli.dll I made sure there weren't extra copies of the DLLs floating around. I copied libmysql.dll from d:\apps\mysql\bin to c:\windows\system32. I stopped and restarted IIS, but still no dice. In my PHP folder (d:\apps\php) I have the following files: install.txt license.txt news.txt php.exe php.gif php.ini php_mbstring.dll php_mysqli.dll php5embed.lib php5isapi.dll php5ts.dll When I installed php and mysql, it didn't give me any mysql stuff so I had to download that separately. However, I couldn't find php_mysql.dll. If I understood what I read (and that's not alltogether likely I guess hehe), php_mysqli.dll is the newer version of that so I downloaded it. Do I still need php_mysql.dll as well? When I went to the mysql download link and searched for "php", the only thing I could find was that mysqli. I did a Google for php_mysql.dll and found a dll download site with it, but not coming from mysql or php themselves I am kinda distrustful of it. PS, phpMyAdmin works fine which really perplexes me because to me, that indicates php and mysql are talking just fine. Ugh! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/126788-problem-with-getting-php-to-talk-to-mysql/ Share on other sites More sharing options...
CroNiX Posted October 2, 2008 Share Posted October 2, 2008 Its because you are using the functions for mysql when you need to use the mysqli functions/methods. http://uk.php.net/mysqli instead of: $db = mysql_connect(localhost,"username","password"); you need: $db = mysqli_connect(localhost,"username","password"); Quote Link to comment https://forums.phpfreaks.com/topic/126788-problem-with-getting-php-to-talk-to-mysql/#findComment-655783 Share on other sites More sharing options...
Maq Posted October 2, 2008 Share Posted October 2, 2008 Try this for you connection: $host="localhost"; $user_name="username"; $password="password"; $db="urls"; $connection = mysql_connect($host, $user_name, $password) or die ("Unable to connect!"); mysql_select_db($db) or die ("Unable to select database!"); Quote Link to comment https://forums.phpfreaks.com/topic/126788-problem-with-getting-php-to-talk-to-mysql/#findComment-655785 Share on other sites More sharing options...
CroNiX Posted October 2, 2008 Share Posted October 2, 2008 Hes using mysqli, not mysql Quote Link to comment https://forums.phpfreaks.com/topic/126788-problem-with-getting-php-to-talk-to-mysql/#findComment-655790 Share on other sites More sharing options...
Maq Posted October 2, 2008 Share Posted October 2, 2008 Yeah, I just realized that... Quote Link to comment https://forums.phpfreaks.com/topic/126788-problem-with-getting-php-to-talk-to-mysql/#findComment-655807 Share on other sites More sharing options...
Strahan Posted October 2, 2008 Author Share Posted October 2, 2008 Thanks guys. Man I feel stupid, banging my head against the wall looking at the php install when it was just bad code hehe. I noticed most of the tutorials I see are using mysql_ calls. Is the mysqli thing new or something? Do mysqli_ and mysql_ functions generally take the same parms or should I only be looking for tuts with mysqli? Thanks again, I really appreciate it! Quote Link to comment https://forums.phpfreaks.com/topic/126788-problem-with-getting-php-to-talk-to-mysql/#findComment-655810 Share on other sites More sharing options...
wildteen88 Posted October 2, 2008 Share Posted October 2, 2008 mysqli_ was introduced when PHP5 was released. It allows you you take advantage of MySQL5's features. the mysqli_* functions behave differently compared to the older mysql_* functions. I would recommend you to read the manual for working with MySQLi. Quote Link to comment https://forums.phpfreaks.com/topic/126788-problem-with-getting-php-to-talk-to-mysql/#findComment-655830 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.