/    Sign up×
Community /Pin to ProfileBookmark

SQL -> MySQL Functions (I need Help)

I am new to databasing, I started using sql with our server, I want to do work outside my office, and the server I have setup uses mysql. To my understanding sql and mysql are similar or the same, am I wrong? This are basic funtions that I use to connect and do simple funtions to my database with sql. Can someone help me rewrite the few code snippets I provided to mysql. I tried doing this myself and I just can’t get it to work. If someone can help, thanks so much, this means alot. I don’t need complex codes, just the basics I provided but in mysql code. Thanks in advance.

DB

[code=php]
<!– INSERT INTO DATABASE –>

<?php

$ser=”111.111.0.0″;
$db=”database”;
$user=”username”;
$pass=”password”;

$conn = odbc_connect($db, $user, $pass);

$conn = odbc_connect($db, $user, $pass);
$query = “INSERT INTO tablename (Entry1, Entry2, Entry3) VALUES (‘$Entry1’, ‘$Entry2’, ‘$Entry3’)”;

odbc_do($conn, $query);

?>
<html>
<!– HTML PAGE CODE HERE –>
</html>
<?php
odbc_close($conn);
?>

<!– UPDATE DATABASE –>

<?php

$ser=”111.111.0.0″;
$db=”database”;
$user=”username”;
$pass=”password”;

$conn = odbc_connect($db, $user, $pass);
$query = “UPDATE tablename SET Entry1 = ‘$Entry1’, Entry2 = ‘$Entry2’, Entry3 = ‘$Entry3’ WHERE Info =’$Info'”;

odbc_do($conn, $query);
?>
<html>
<!– HTML PAGE CODE HERE –>
</html>
<?php
odbc_close($conn);
?>

<!– DELETE FROM DATABASE –>

<?php

$ser=”111.111.0.0″;
$db=”database”;
$user=”username”;
$pass=”password”;

$conn = odbc_connect($db, $user, $pass);
$query = “DELETE FROM tablename WHERE Entry1 = ‘$Entry1′”;

odbc_do($conn, $query);
?>
<html>
<!– HTML PAGE CODE HERE –>
</html>
<?php
odbc_close($conn);
?>

<!– VIEW INFO FROM DATABASE –>

<?php

$ser=”111.111.0.0″;
$db=”database”;
$user=”username”;
$pass=”password”;

$id = $_GET[‘id’];
$conn = odbc_connect($db, $user, $pass);
$query = “SELECT * FROM tablename WHERE Entry1 = ‘” . $id . “‘”;

odbc_do($conn, $query);
?>
<html>
<?php
while($myrow=odbc_fetch_array($result)) {
echo(‘
Entry1: <input name=”Entry1″ value=”‘.$myrow[‘Entry1’].'”><br>
Entry2: <input name=”Entry2″ value=”‘.$myrow[‘Entry2’].'”><br>
Entry3: <input name=”Entry3″ value=”‘.$myrow[‘Entry3’].'”><br>
‘);
}
}
?>
</html>
<?php
odbc_close($conn);
?>
[/code]

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@ShrineDesignsJul 30.2004 — try this:[code=php]<?php
$link = mysql_pconnect('111.111.0.0', 'username', 'password');
mysql_select_db('database', $link);

$result = mysql_query("INSERT INTO tablename (Entry1, Entry2, Entry3) VALUES ('$Entry1', '$Entry2', '$Entry3')", $link);
?>[/code]
[code=php]<?php
$link = mysql_pconnect('111.111.0.0', 'username', 'password');
mysql_select_db('database', $link);

$result = mysql_query("UPDATE tablename SET Entry1 = '$Entry1', Entry2 = '$Entry2', Entry3 = '$Entry3' WHERE Info = '$Info'", $link);
?>[/code]
[code=php]<?php
$link = mysql_pconnect('111.111.0.0', 'username', 'password');
mysql_select_db('database', $link);

$result = mysql_query("DELETE FROM tablename WHERE Entry1 = '$Entry1'", $link);
?>[/code]
[code=php]<?php
$link = mysql_pconnect('111.111.0.0', 'username', 'password');
mysql_select_db('database', $link);

$result = mysql_query("SELECT * FROM tablename WHERE Entry1 = '{$_GET['id']}'", $link);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "Entry1: <input name="Entry1" id="Entry1" value="{$row['Entry1']}"><br>
Entry2: <input name="Entry2" id="Entry2" value="{$row['Entry2']}"><br>
Entry3: <input name="Entry3" id="Entry3" value="{$row['Entry3']}"><br>
";
}
?>
[/code]
Copy linkTweet thisAlerts:
@d_brandusaauthorJul 30.2004 — Do I need to close the connection like in sql?
Copy linkTweet thisAlerts:
@ShrineDesignsJul 30.2004 — the function mysql_pconnect() creates a persistant database connection, you can not use mysql_close() on it, you can only use mysql_close() with mysql_connect()
Copy linkTweet thisAlerts:
@d_brandusaauthorJul 30.2004 — I have my "INSERT" like this: I get no errors, yet not data is put into the database!?

[code=php]
<?php
$conn = mysql_connect('database', 'username', 'password');
mysql_select_db('database', $conn);

$result = mysql_query("INSERT INTO cart_owners (First_Name, Last_Name) VALUES ('$First_Name', '$Last_Name')", $conn);
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Form</title>
</head>

<body>
<form action="insert.php" method="post" enctype="multipart/form-data">
First Name: <input name="First_Name"><br>
Last Name: <input name="Last_Name"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
<?php
mysql_close($conn);
?>
[/code]
Copy linkTweet thisAlerts:
@crh3675Jul 30.2004 — 
To my understanding sql and mysql are similar or the same
[/quote]


Just a bit of information, SQL stands for structured query language. SQL is pretty much the same for all databases on all platforms. Some DB's enhance their functionalty and have proprietary statement calls but it all remains the same.
Copy linkTweet thisAlerts:
@ShrineDesignsJul 31.2004 — [code=php]<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Form</title>
</head>
<body>
<?php
if($_POST)
{
$conn = mysql_connect('database', 'username', 'password');
mysql_select_db('database', $conn);
$result = mysql_query("INSERT INTO cart_owners (First_Name, Last_Name) VALUES ('{$_POST['First_Name']}', '{$_POST['Last_Name']}')", $conn);

if($result !== false && mysql_affected_rows($conn) != 0)
{
echo "information sucessfully added to database";
}
else
{
echo mysql_error($conn);
}
mysql_close($conn);
}
?>
<form action="" method="post" enctype="multipart/form-data">
First Name:
<input name="First_Name"><br>
Last Name:
<input name="Last_Name"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
[/code]
×

Success!

Help @d_brandusa spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...