Jump to content

Archived

This topic is now archived and is closed to further replies.

Neptunus Maris

A MySQL-Link ERROR

Recommended Posts

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/rdrvisio/public_html/install.php on line 18


Thats the problem I cant figure out.  Here is the line of code.  Scroll down and you'll find where I noted line 18. (NOTE: its only a part of a script)

<?php

//this will install and populate tables in your database
include "config.php";
connect();

//start with the subscribers

$installsubs = <<<HERE
CREATE TABLE `subscribers` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL default '',
`email` varchar(100) NOT NULL default '',
`date_sub` datetime NOT NULL '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
);
HERE;
$result = mysql_query($installsubs, $dbconn) or die(mysql_error());    <----LINE 18
print "Subscriber table created!";

=====================================

I just cant figure it out at all...please help me.


Thank you in advance
Neptune

Share this post


Link to post
Share on other sites
i think the problem is that your connect() function (which i assume is in your included config.php) is not connecting to the database.  check to make sure the path to config.php is correct. your include statement assumes it is in the same directory, because you do not have a path shown there. Is it really in the same directory? Also, check to make sure the connection info in connect() is correct. Is the host, user name, password, and db name correct?  Do you have mysql_error()'s attached to those function calls to report an error in connection?

Share this post


Link to post
Share on other sites
The connect() is correct and the code within it o connect to te database.  The included file "config.php" is i the same directory.  But as for the mysql_error() function, i thought that was a automatic function that was already made within PHP, if not I didnt know you had to make it.  It's just that in the books Ive read it said it was a pre-defined function for PHP.

This is what my connect() looks like in my config.php.

[sub]function connect() { //connects the database
global $servername, $username, $password, $dbname;
$dbconn = mysql_connect($servername, $username, $password) or die(mysql_error());
$select = mysql_select_db($dbname, $dbconn) or die(mysql_error());
} //end connect[/sub]

Thanks
Neptune

Share this post


Link to post
Share on other sites
mysql_error() [i]is[/i] a built in function.

okay your problem is that your $dbconn in your function is a local variable, so your connection does not apply to the rest of your script.

you need to return the variable and instead of doing just connect(); in your main script, do like

$connection = connect();

and then use $connection in your mysql_query

Share this post


Link to post
Share on other sites
Yeah that doesnt work either and then when I took the $dbconn(or what you told me $connection) out of the mysql_query.  I got this the next time around:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'unsigned NOT NULL '0000-00-00 00:00:00', PRIMARY KEY (`id`) )' at line 5

thats on line 5 of install.php, here are the first 19 lines of install.php;:

<?php

//this will install and populate tables in your database
include "config.php";
connect();

//start with the subscribers

$installsubs = <<<HERE
CREATE TABLE `subscribers` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL default '',
`email` varchar(100) NOT NULL default '',
`date_sub` datetime unsigned NOT NULL '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
);
HERE;
$result = mysql_query($installsubs) or die(mysql_error());
print "Subscriber table created!";

--------------------------
And this is my server info:

General server information:
Operating system Linux
Kernel version 2.6.17.1
Machine Type i686
Apache version 1.3.36 (Unix)
PERL version 5.8.7
Path to PERL /usr/bin/perl
Path to sendmail /usr/sbin/sendmail
Installed Perl Modules Click to View
PHP version 5.0.4
MySQL version 4.1.21-standard-log
cPanel Build 10.9.0-CURRENT 28
Theme cPanel X v2.5.0

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.