my code


by tkngrafik

Este script me sirve para conectarme a la base de datos por medio de php. Es otra opción que me parece muy buena a la hora de crear la conexión.

Snippet options

Download: Download snippet as conectar-a-una-base-de-datos-mysql-segunda-opcion.php.
Copy snippet: For this you need a free my code account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

//asignar variables
$ip = 'localhost';
$usuario = 'root';
$password = ''aqui pongo la contraseña ";
$db_name = 'aqui pongo el nombre de la base de datos';
//conexion base de datos
$conn = mysql_pconnect($ip,$usuario,$password) or die();
//seleccionar base de datos
$huboerror = mysql_select_db($db_name,$conn) or die();
//si el formulario se envia
if ( !empty($_POST['submit'])){
	$query = "INSERT INTO `noticias` (titulo,autor,categoria,datepicker,texto) VALUES('{$_POST['titulo']}','{$_POST['autor']}','{$_POST['categoria']}','{$_POST['datepiker']}','{$_POST['texto']}')";
	$response = mysql_query($query, $conn);

Create a free my code account now.

my code is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.