help4code

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()); } ?> Advertisements

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 […]

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/>”; ?>

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/>; ?>

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); ?>

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/>”; } ?>