note 94853 deleted from function.mysql-query by danbrown

From: Date: Mon, 30 Nov 2009 13:07:09 +0000
Subject: note 94853 deleted from function.mysql-query by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-163412@lists.php.net to get a copy of this message
Note Submitter: jbud at jbud dot co dot cc ---- This is a simple function to use for doing mysql querys config.php: <?php $config_url = "localhost"; $config_user = "Goober"; $config_password = "I4m4k1ttyc4t"; ?> functions.php: <?php function doSql($query, $type) { require('config.php'); $doSql_Connect = mysql_connect($config_url, $config_user, $config_password); mysql_select_db($config_db, $doSql_Connect); if ($type == "RETURNARRAY") { return mysql_fetch_array(mysql_query($query, $doSql_Connect)); } elseif ($type == "RETURN") { return mysql_query($query, $doSql_Connect); } } ?> usage: <?php $mysqlarray = doSql("SELECT * FROM stuff LIMIT 10","RETURNARRAY"); print_r($mysqlarray); if (!doSql("INSERT INTO stuff ('name', 'age') VALUES ('bill', '86')","RETURN")){ die("Failed to insert<br>".mysql_error()); } ?>

« previous php.notes (#163412) next »