i have created 2 files namely db.php and functions.php when i run the db.php many errors coming like
Connection Successfull
Warning: fwrite(): supplied argument is not a valid stream resource in C:\xampp\htdocs\Db2File\functions.php on line 45
Warning: fwrite(): supplied argument is not a valid stream resource in C:\xampp\htdocs\Db2File\functions.php on line 45
Warning: fwrite(): supplied argument is not a valid stream resource in C:\xampp\htdocs\Db2File\functions.php on line 45
Warning: fwrite(): supplied argument is not a valid stream resource in C:\xampp\htdocs\Db2File\functions.php on line 45
Warning: fwrite(): supplied argument is not a valid stream resource in C:\xampp\htdocs\Db2File\functions.php on line 45
Warning: fwrite(): supplied argument is not a valid stream resource in C:\xampp\htdocs\Db2File\functions.php on line 45
Warning: fwrite(): supplied argument is not a valid stream resource in C:\xampp\htdocs\Db2File\functions.php on line 45
Warning: fwrite(): supplied argument is not a valid stream resource in C:\xampp\htdocs\Db2File\functions.php on line 45
Warning: fwrite(): supplied argument is not a valid stream resource in C:\xampp\htdocs\Db2File\functions.php on line 45
Warning: fwrite(): supplied argument is not a valid stream resource in C:\xampp\htdocs\Db2File\functions.php on line 45
Warning: fwrite(): supplied argument is not a valid stream resource in C:\xampp\htdocs\Db2File\functions.php on line 45
Warning: fwrite(): supplied argument is not a valid stream resource in C:\xampp\htdocs\Db2File\functions.php on line 45
Warning: fwrite(): supplied argument is not a valid stream resource in C:\xampp\htdocs\Db2File\functions.php on line 45
Warning: fwrite(): supplied argument is not a valid stream resource in C:\xampp\htdocs\Db2File\functions.php on line 45
Warning: fwrite(): supplied argument is not a valid stream resource in C:\xampp\htdocs\Db2File\functions.php on line 45
Warning: fwrite(): supplied argument is not a valid stream resource in C:\xampp\htdocs\Db2File\functions.php on line 45
Warning: fwrite(): supplied argument is not a valid stream resource in C:\xampp\htdocs\Db2File\functions.php on line 45
Warning: fwrite(): supplied argument is not a valid stream resource in C:\xampp\htdocs\Db2File\functions.php on line 45
Warning: fwrite(): supplied argument is not a valid stream resource in C:\xampp\htdocs\Db2File\functions.php on line 45
Warning: fwrite(): supplied argument is not a valid stream resource in C:\xampp\htdocs\Db2File\functions.php on line 45
Warning: fwrite(): supplied argument is not a valid stream resource in C:\xampp\htdocs\Db2File\functions.php on line 45
Warning: fwrite(): supplied argument is not a valid stream resource in C:\xampp\htdocs\Db2File\functions.php on line 45
Warning: fwrite(): supplied argument is not a valid stream resource in C:\xampp\htdocs\Db2File\functions.php on line 45
Data appended to the file
Status changed from 0->1
Warning: fclose(): supplied argument is not a valid stream resource in C:\xampp\htdocs\Db2File\functions.php on line 65
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\Db2File\functions.php on line 66
Code:(db.php)
Code: Select all
<?php
include("functions.php");
//include("functions.php");
dbConnection();
//Main logic Code
fetchRecord();
processData();
?>Code: Select all
<?php
function dbConnection(){
//connection parameters
$username = "root";
$password = "";
$dbhost = "localhost";
//connection to database
$dbconnection = mysql_connect($dbhost, $username, $password) or die("Could not connect to MySQL Database". mysql_error());
//selecting a database
$dbselect = mysql_select_db("test", $dbconnection);
//checking whether the database is selected
if(!$dbselect){
echo "Error in Connection String";
}
else
{
echo "Connection Successfull";
}
echo "<br/>";
}
function fetchRecord(){
$query="SELECT * FROM phone_dummy";
$result=mysql_query($query);
//$num=mysql_numrows($result);
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
while ($row = mysql_fetch_assoc($result)) {
$phone_id = $row['phone_id'];
$phone_number = $row['phone_number'];
$name = $row['name'];
$address = $row['address'];
$status = $row['status'];
$export="$phone_id|$phone_number|$name|$address|$status"."\r\n";
$stringData = "$export";
fwrite($fh, $stringData);
if($status == 0){
$updatequery = "UPDATE phone_dummy SET status = 1";
mysql_query($updatequery);
}
}
}
function fileOpen(){
$header="ID|Phone|Name|Address|Status";
$myFile = "phonedetails.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
}
function fileWrite(){
$stringData = "$header"."\r\n";
fwrite($fh, $stringData);
}
function fileClosing(){
fclose($fh);
mysql_free_result($result);
}
function processData(){
fileOpen();
echo "Data appended to the file"."<br>";
echo "Status changed from 0->1";
fileClosing();
}
?>