PHP Code:
<?
class database
{
private $db_handle;
private $user_name;
private $password;
private $data_base;
private $host_name;
private $sql;
private $results;
function __construct($host="localhost",$user,$passwd)
{
$this->db_handle = mysql_connect($host,$user,$passwd);
}
function dbSelect($db)
{
$this->data_base = $db;
if(!mysql_select_db($this->data_base, $this->db_handle))
{
error_log(mysql_error(), 3, "/phplog.err");
die("Error connecting to Database");
}
}
function executeSql($sql_stmt)
{
$this->sql = $sql_stmt;
$this->result = mysql_query($this->sql);
}
function fileSaving()
{
while($record = mysql_fetch_object($this->result))
{
$fileToBCopied = $record->imageURL;
$fileArray = explode("/",$fileToBCopied);
$arrayLength = count($fileArray);
$newFileName = $fileArray[$arrayLength-1];
$fpRead = fopen($fileToBCopied,"r");
if(file_exists("C:\\images\\$newFileName"))
{
continue;
}
$fpWrite = fopen("C:\\images\\$newFileName", "w");
$buf = file_get_contents($fileToBCopied);
fwrite($fpWrite, $buf);
}
echo "<strong>File copying operation has been over</strong>";
}
}
[COLOR="Blue"]$db = new database("localhost","root","");[/COLOR]
[COLOR="Red"]$db-> dbSelect("images");[/COLOR]
$sql = "SELECT imageURL FROM image";
$db->executeSql($sql);
$db->fileSaving();
?>
Try the above code and at the time of database object instantiation pass your database user details and password here i've used user root and an empty password.
The red color line is used to specify your database here its name is images.
It worked for me to achieve what you've mentioned in your posting.
let me know if you have any difficulty with the above code.
Bookmarks