sarah... rather than deal with classes/objs... (at least initially) just create a simple php/mysql app that sets up the user/passwd/host for the db, and see if you can do a successful mysql_connect.... check the return/error codes to see if the call/code works this will quickly tell you if you actually have php/mysql setup properly... once you've done this... you can get into the guts of your app, to determine where the prob is.... -bruce -----Original Message----- From: Sarah <weregirl@xxxxxxxxxxxxxxxx> Sent: Feb 5, 2005 7:41 AM To: php-general@xxxxxxxxxxxxx Subject: Problems with PHP and MySQL Hi, I'm relatively new to PHP, but have already written a few functional web-based scripts. I recently decided to implement a MySQL-based system, but hit the following problem... I have PHP version 5.03, and MySQL v 4.19. I downloaded and compiled both, and both work perfectly alone. However, when I run a command-line app to manipulate my database, I get the following error: __________________________________________________________________________ veep@tinsel:~# ./useradmin -a -u unclebulgaria -p uberwomble constructor called Fatal error: Call to undefined function mysql_connect() in veep/useradmin on line 16 Fatal error: Call to undefined function mysql_close() in /veep/useradmin on line 22 veep@tinsel:~# __________________________________________________________________________ You might think 'Aah! the doofus has forgotten to link MySQL into the compiled PHP interpreter'. However, my phpinfo() page gives the following information: __________________________________________________________________________ Configure command: './configure' '--with-apxs2=/opt/apache/sbin/apxs' '--prefix=/usr' '--sysconfdir=/etc/php5' '--with-dba' '--with-db4' '--with-auth' '--with-zlib' '--with-tiff' '--with-jpeg' '--with-mysql=/usr' __________________________________________________________________________ And... __________________________________________________________________________ MySQL-related data: mysql MySQL Support enabled Active Persistent Links 0 Active Links 0 Client API version 4.1.9 MYSQL_MODULE_TYPE external MYSQL_SOCKET /tmp/mysql.sock MYSQL_INCLUDE -I/usr/include/mysql MYSQL_LIBS -L/usr/lib -lmysqlclient Directive Local Value Master Value mysql.allow_persistent On On mysql.connect_timeout 60 60 mysql.default_host localhost localhost mysql.default_password wurms wurms mysql.default_port 3306 3306 mysql.default_socket no value no value mysql.default_user wiggly wiggly mysql.max_links Unlimited Unlimited mysql.max_persistent Unlimited Unlimited mysql.trace_mode Off Off _________________________________________________________________________ Finally, the client program is: _________________________________________________________________________ #!/usr/bin/php <?php class UserDB { static $user='wiggly'; static $pass='wurms'; static $db='multimedia_access'; private $m_link; private $m_live; function __construct() { print("constructor called\n"); $this->m_link = mysql_connect('localhost', self::$user, self::$pass); $this->m_live = mysql_select_db(self::db); } function __destruct() { mysql_close($this->m_link); print("destructor called"); } function Add($u, $p) { $H = md5($u, true); // $R = mysql_query("INSERT INTO users (userkey, user, password) values ($H, $u, $p)", $this->m_link); $S = mysql_real_escape_string("INSERT INTO users (userkey, user, password) values ('$H', '$u', '$p')", $this->m_link); $R = mysql_query($S, $this->m_link); if (!$R) { printf("SQL query error during Add operation\n"); } return $R; } function Delete($u) { $H=md5($u, true); $R=mysql_query("DELETE FROM users WHERE userkey=$H"); if ($R) { $R=mysql_query("DELETE FROM iplist WHERE userkey=$H"); } if (!$R) { printf("SQL query error during Add operation\n"); } return $R; } function Replace($u, $p) { return 0; } function Tabulate() { $R=mysql_query("SELECT user,password FROM TABLE users"); if (!$R) { printf("SQL query error during List operation\n"); } $N=mysql_num_rows($R); if ($N > 0) { while($Row = mysql_fetch_row($R)) { foreach($Row as $K => $V) { $Col = mysql_field_name($R ,$K); printf("%s='%s', ", $Col, $V); } printf("\n"); } } return $R; } } function Usage($text) { printf("useradmin:\n\tuseradmin (-a|-d|-r) -u <user name> -p <password>\n\n"); printf("\t-a - add given user.\n"); printf("\t-d - delete given user.\n"); printf("\t-r - replace given user.\n"); printf("\t-l - list all users and passwords in the database.\n"); printf("\n\t%s\n\n", $text); exit(0); } function do_add($u, $p) { $D=new UserDB(); return $D->Add($u, $p); } function do_del($u) { $D=new UserDB(); return $D->Delete($u); } function do_rep($u, $p) { $D=new UserDB(); return $D->Replace($u, $p); } function do_list() { $D=new UserDB(); return $D->Tabulate(); } function main() { $password=''; $username=''; $command['a']=false; $command['d']=false; $command['r']=false; $command['l']=false; $cmdcount=0; $opt = getopt("ladru:p:h"); foreach ($opt as $k => $v) { switch($k) { case 'h': Usage("Help information."); break; case 'p': if ($v) { $password=$v; } break; case 'u': if ($v) { $username=$v; } break; case 'a': $command[$k]=true; $cmdcount += 1; break; case 'd': $command[$k]=true; $cmdcount += 1; break; case 'r': $command[$k]=true; $cmdcount += 1; break; case 'l': $command[$k]=true; $cmdcount += 1; break; default: } } if ($cmdcount > 1) { Usage("You may specifiy no more than one command at a time"); } else if ($cmdcount < 1) { Usage("You must specify one of add, delete, replace"); } if ($command['a'] == true) { if ($username == false || $password == false) { Usage("You must specify the username and password when adding an user"); } do_add($username, $password); } else if ($command['r'] == true) { if ($username == false || $password == false) { Usage("You must specify the username and password when replacing an user"); } do_del($username); } else if ($command['d'] == true) { if ($username == false) { Usage("You must specify the username when deleting an user"); } else if ($password != false) { Usage("The password is superfluous for the delete comand"); } do_rep($username, $password); } else if ($command['l'] == true) { if ($username != false || $password != false) { Usage("Superfluous arguments given to the list command"); } do_list($username, $password); } exit(0); } main(); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php