Jump to content

Conectare Mysql Dintr-Un Alt Fisier


Andrei Manolache

Recommended Posts

Ca sa scutesc din spatiu si timp as vrea sa fac conectarea la baza de date dintr-un fisier extern care va fi numit connectdb.php

Ce trebuie sa adaug in fisierul connectdb.php si ce trebuie sa modific in fisierul existent?

 

Momentan arata asa:

		<?php
			$con=mysqli_connect("mysql3.000webhost.com","a5691033_cc","andrei123","a5691033_cc");
			// Check connection
			if (mysqli_connect_errno()) {
			  echo "Failed to connect to MySQL: " . mysqli_connect_error();
			}

			$result = mysqli_query($con,"SELECT * FROM p_capital");

			while($row = mysqli_fetch_array($result)) {
			  echo "<tr>";
			  echo "<td>" . $row['suma'] . "</td>";
			  echo "</tr>";
			}
			echo "</table>";

			mysqli_close($con);
		?>
Link to comment
Share on other sites

  • Moderators

connectdb.php

<?php 

$con=mysqli_connect("mysql3.000webhost.com","a5691033_cc","andrei123","a5691033_cc");

if (mysqli_connect_errno()) 
{
	die("Failed to connect to MySQL: " . mysqli_connect_error());
}

?>

fisierul tau:

<?php

require_once('connectdb.php');

$result = mysqli_query($con,"SELECT * FROM p_capital");

$HTML = "<table>";

while($row = mysqli_fetch_array($result)) 
{
	$HTML .= <<<HTML
		<tr>
		<td>{$row['suma']}</td>
		</tr>
HTML;
}

$HTML .= "</table>";

echo $HTML;

mysqli_close($con);
?>

L-am scris direct in notepad, n-am stat sa vad daca-i bun.

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.