Leave a comment

How to import .sql file in mysql using php

<?php
    
    $con = mysql_connect(“localhost”, “root”, “admin”) or die(“Database connection failed: “.mysql_error());
    $db = mysql_select_db(“SQL_FILE”, $con) or die(“Database selectio failed: “.mysql_error());

$path = //your file path
$sql_filename = ‘wp_options.sql’;
$sql_contents = file_get_contents($path.$sql_filename);
$sql_contents = explode(“@@”, $sql_contents);
foreach($sql_contents as $query){
       $result = mysql_query($query) or die(“Database query failed: “.mysql_error());
}
?>

Leave a comment

How to insert video in MySQL Database in PHP?

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
</head>

<body>
<table>
<form action=”upload.php” method=”post” enctype=”multipart/form-data”>
<tr><td><label>Video Name : </label></td><td><input type=”text” name=”vname”/></td></tr>
<tr><td><label>Category : </label></td><td><input type=”text” name=”cat”/></td></tr>
<tr><td><label>Keywords : </label></td><td><input type=”text” name=”kwd”/></td></tr>
<tr><td><label>Upload file: </label></td><td><input type=”file” name=”uploaded” /></td></tr>
<tr><td></td><td><input type=”submit” value=”Upload” /></td></tr>
</form>
</tr>
</table>
<?php
$videoname = $_POST['vname'];
$category = $_POST['cat'];
$keyword = $_POST['kwd'];
$path = $_POST['uploaded'];
$target = “C:/xampp/htdocs/wordpress/wp-content/themes/metube-theme/upload/”;
$target = $target . basename($_FILES['uploaded']['name']);

if(empty($videoname) || empty($category) || empty($keyword)){
echo “<b>Please fill all field then try agian</b>”;
}else{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)){
echo “The file (“. basename($_FILES['uploaded']['name']). “) has been upload”; 
}
else{
echo “Sorry, there was a problem uploading your file.”;
}
echo “<br/>”;
}
?>

<?php
$path = str_replace(“C:/xampp/htdocs”,”http://localhost”,$target);
$query = “INSERT INTO videos(videoname, category, keywords, path)”;
$query .= “VALUE (‘$videoname’, ‘$category’, ‘$keyword’, ‘$path’)”;
$result = mysql_query($query);

?>
</body>
</html>

Leave a comment

How to get value from MySQL Database in PHP?

<?php

$sql = “SELECT  * FROM yourfieldname”;

$query = mysql_query($sql);

$result = mysql_fetch_array($query);

echo $result . “<br/>”;

?>

Leave a comment

How to insert Value in MySql Database in PHP ?

<?php

$sql = “INSERT INTO yourtablename(yourfiledname) VALUE(‘$_POST[yourvalue]‘)”;

$result = mysql_query($sql);

echo $result . <br/>;

?>

Leave a comment

How To Connect MySQL Database in php?

<?php

$con = mysql_connect(“localhost”, “root”, “yourmysqlpassword”) or die(mysql_error());

          mysql_select_db(“yourdatabasename”, $con);

if($con){

echo “It\’s working”;

}

else

{

echo “Not working”;

}

mysql_close($con);

?>

Leave a comment

How to read CSV file in PHP

<?php

$file_handle = fopen(“yourcsv.csv”, “r”);

while($values = fgetcsv($file_handle))

{

foreach($values as $value);

echo $value . “<br/>”;

}

?>

Follow

Get every new post delivered to your Inbox.