 |
Apache2Triad Help, Support and Development The apache2triad help , support and development forums
|
| View previous topic :: View next topic |
| Author |
Message |
talassh
Joined: 12 May 2006
Posts: 5
|
| Posted: Fri May 12, 2006 7:54 pm Post subject: php/mysql doing nothing; help me |
|
|
[13-May-2006 05:24:07] PHP Fatal error: Call to undefined function: mysql_create_db()
here's my code
im trying to retrive data from Mysql using php, simply its not working
doing nothing
and also getting no errors but nothing is happening
anything, any idea any basic code to check that is it working php/mysql???
here my code is:
Code:
<?
$connection = mysql_connect("localhost","root","*******");
if (!$connection){
echo mysql_errno().": ".mysql_error()."<br/>";
exit;
}
if(mysql_select_db("NOTESTIPS_TEST")){
echo("Database NOTESTIPS_TEST already exists<br>");
mysql_query("DROP DATABASE NOTESTIPS_TEST");
echo("Database NOTESTIPS_TEST removed<br>");
}
if (mysql_create_db("NOTESTIPS_TEST")){
echo("Database NOTESTIPS_TEST created<br>");
}
mysql_query("CREATE TABLE person (
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (id),
firstname VARCHAR(25),
lastname VARCHAR(25))"
);
echo("Database TABLE person created<br>");
mysql_query("INSERT INTO person (firstname, lastname) VALUES ('Mike',
'Golding')");
mysql_query("INSERT INTO person (firstname, lastname) VALUES ('John',
'Smith')");
echo("TABLE person rows inserted<br>");
echo("Retriving Rows<br><br>");
//RETURN RESULT
$result = mysql_query ("SELECT * FROM person");
// fetch the current row into the array $row
while ($row = mysql_fetch_row($result))
{
// print the values of the attributes
for ($i=0; $i<mysql_num_fields($result); $i++)
echo $row[$i] . " ";
echo "<br />";
}
mysql_close();
?>
[edited From another thread]
I'm unable to retrive data from mysql using php, it displays a blank page.
any sample code to chek it!!
seperatle mysql and php are working but when i try to combine it showing nothing no error but a blank page |
|
| Back to top |
|
Joshua Meadows (DemoRic)
Joined: 29 Dec 2004
Posts: 785
Location: S.E. Kansas
|
| Posted: Fri May 12, 2006 9:53 pm Post subject: |
|
|
Firstly, don't double post. Please respect others time.
Anyways, that being said the reason for the blank page is that php errors aren't sent to the client by the default setup. There are many ways of changing this. You can edit the php.ini file, or as I prefer I use virtual hosts for local, and for other sites in my httpd.conf.
Code: NameVirtualHost *:80
#localhost
<VirtualHost localhost:80>
ServerAdmin admin@yourhost.com
DocumentRoot c:/apache2triad/htdocs
ServerName localhost
ErrorLog logs/localhost_error.log
CustomLog logs/localhost_access.log common
#display php errors
php_value register_globals 0
php_value error_reporting 2047
php_value display_errors 1
</VirtualHost>
Create DB example.
Code:
<?
$connection = mysql_connect("localhost","root","yourpassword");
if (!$connection){
echo mysql_errno().": ".mysql_error()."<br/>";
exit;
}
$sql = 'CREATE DATABASE NOTESTIPS_TEST';
if (mysql_query($sql, $connection)) {
echo "Database my_db created successfully\n";
} else {
echo 'Error creating database: ' . mysql_error() . "<br />\n";
}
$db_selected = mysql_select_db('NOTESTIPS_TEST', $connection);
if (!$db_selected) {
die ('Can\'t use pesron : ' . mysql_error());
}
$sql =<<<HERE
CREATE TABLE `person` (
`firstname` VARCHAR( 25 ) NOT NULL ,
`lastname` VARCHAR( 25 ) NOT NULL
) TYPE = MYISAM ;
HERE;
echo "<br /><br />".$sql."<br />";
if (mysql_query($sql,$connection)){
echo("Database TABLE person created<br>");
} else {
echo 'Error creating table: ' . mysql_error() . "<br />\n";
}
$sql =<<<HERE
INSERT INTO `person` ( `firstname` , `lastname` )
VALUES (
'Mike', 'Golding'
);
HERE;
if (mysql_query($sql,$connection)){
echo("TABLE person rows inserted<br>");
$sql =<<<HERE
INSERT INTO `person` ( `firstname` , `lastname` )
VALUES (
'John', 'Smith'
);
HERE;
mysql_query($sql,$connection);
} else {
echo 'Error creating table: ' . mysql_error() . "<br />\n";
}
echo("Retriving Rows<br><br>");
//RETURN RESULT
$result = mysql_query ("SELECT * FROM person");
// fetch the current row into the array $row
while ($row = mysql_fetch_row($result))
{
// print the values of the attributes
for ($i=0; $i<mysql_num_fields($result); $i++)
echo $row[$i] . " ";
echo "<br />";
}
mysql_close();
?>
P.S. Sorry if the code is a little convulted, I too am learning php/mysql. |
|
| Back to top |
|
talassh
Joined: 12 May 2006
Posts: 5
|
| Posted: Fri May 12, 2006 10:31 pm Post subject: still nothing |
|
|
im using first time fourm so i dont know ; i respect the time of every person
and thanks for responding
now this time
[13-May-2006 06:15:53] PHP Parse error: syntax error, unexpected T_SL in G:\apache2triad\htdocs\testmysql02.php on line 19
and before i think i got fatal error
call to undefined function mysql_create_db() |
|
| Back to top |
|
Joshua Meadows (DemoRic)
Joined: 29 Dec 2004
Posts: 785
Location: S.E. Kansas
|
| Posted: Fri May 12, 2006 10:57 pm Post subject: |
|
|
Quote: and before i think i got fatal error
call to undefined function mysql_create_db()
The function mysql_create_db() is deprecated. It is preferable to use mysql_query() to issue a sql CREATE DATABASE statement instead. http://us2.php.net/manual/en/function.mysql-create-db.php
Quote: PHP Parse error: syntax error, unexpected T_SL in G:\apache2triad\htdocs\testmysql02.php on line 19
Check around line 19 for a missing ; character or some other syntax problem
Also, here's a little cleaner version of the example:
Code: <?
$text="<html><body>";
$connection = mysql_connect("localhost","root","yourpassword");
if (!$connection){
$text.= mysql_errno().": ".mysql_error()."<br/>";
exit;
}
$sql = 'CREATE DATABASE NOTESTIPS_TEST';
if (mysql_query($sql, $connection)) {
$text.= "Database my_db created successfully\n";
} else {
$text.= 'Error creating database: ' . mysql_error() . "<br />\n";
}
$db_selected = mysql_select_db('NOTESTIPS_TEST', $connection);
if (!$db_selected) {
die (mysql_error());
}
$sql ="CREATE TABLE `person` (`firstname` VARCHAR(25) NOT NULL,`lastname` VARCHAR(25) NOT NULL) TYPE = MYISAM ;";
if (mysql_query($sql,$connection)){
$text.=("Database TABLE person created<br>");
} else {
$text.= 'Error creating table: ' . mysql_error() . "<br />\n";
}
$arraysql[]="INSERT INTO `person` (`firstname`,`lastname`)VALUES('Mike','Golding');";
$arraysql[]="INSERT INTO `person` (`firstname`,`lastname`)VALUES('John','Smith');";
$arraysql[]="INSERT INTO `person` (`firstname`,`lastname`)VALUES('Joshua','Meadows');";
$arraysql[]="INSERT INTO `person` (`firstname`,`lastname`)VALUES('Vlad','Mancini');";
foreach ($arraysql as $sqlItem) {
if (mysql_query($sqlItem,$connection)){
$text.=$sqlItem."<br />\n";
mysql_query($sql,$connection);
} else {
$text.= 'Error creating table: ' . mysql_error() . "<br />\n";
}
}
$text.=("Retriving Rows<br><br>");
//RETURN RESULT
$result = mysql_query ("SELECT * FROM person");
// fetch the current row into the array $row
while ($row = mysql_fetch_row($result))
{
// print the values of the attributes
for ($i=0; $i<mysql_num_fields($result); $i++)
$text.= $row[$i] . " ";
$text.= "<br />";
}
mysql_close();
$text.="</body></html>";
print $text;
?> |
|
| Back to top |
|
talassh
Joined: 12 May 2006
Posts: 5
|
| Posted: Fri May 12, 2006 11:11 pm Post subject: Thanks |
|
|
atleast i saw the page
THANKS A LOT!
now i can do the rest.... try
thanks again |
|
| Back to top |
|
Joshua Meadows (DemoRic)
Joined: 29 Dec 2004
Posts: 785
Location: S.E. Kansas
|
| Posted: Fri May 12, 2006 11:22 pm Post subject: |
|
|
| That's what I'm here for is help. Just keep studying, learning, and remember to grow with past failures and help others with your learned success. |
|
| Back to top |
|
| |
|