Questions about Aura sql

38 views
Skip to first unread message

Thị Đài Trang Lê

unread,
Mar 25, 2015, 11:29:52 AM3/25/15
to aur...@googlegroups.com
Dear 
I have a code and database look like image
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<?php
$db=mysql_connect("localhost","root","");
if(!$db)
{
echo"can not connect";
exit;
}
$db_selected=mysql_select_db("user",$db);
if(!$db_selected)
{
died("can not connect".mysql_error());
}
echo "success connect to database";
echo"</br>";
echo "Show database";
echo"</br>";

$result=mysql_query("select * from admin");

if(mysql_num_rows($result)<>0)
{
while($row=mysql_fetch_row($result))
{
print_r($row);
echo"</br>";
}
}

echo "insert database";
echo"</br>";
if(isset($_POST['insert']))
{
$name=$_POST['name'];
$age=$_POST['age'];
$phone=$_POST['phone'];
$sql=mysql_query("insert into admin values ( '$name','$age','$phone')");
}


mysql_close($db);
?>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <label>
    <input type="text" name="name" id="name" />
  </label>
  <label>
    <input type="text" name="age" id="age" />
  </label>
  <label>
    <input type="text" name="phone" id="phone" />
  </label>
  <label>
    <input type="submit" name="insert" id="insert" value="insert" />
  </label>
</form>
</body>
</html>

temporary , you do not need to pay attend my code
I read your Aura sql ,dowload and unzip  Aura/sql/2.4.2 (source https://github.com/auraphp/Aura.Sql/releases)then I go E:/aurasql/tests/unit( in cdm.exe) then I type phpunit -c tests/unit/ (it run succesful).the next step i see you type (in Lazy Connection Instance
<?php
use Aura\Sql\ExtendedPdo;

$pdo = new ExtendedPdo(
    'mysql:host=localhost;dbname=test',
    'username',
    'password',
    array(), // driver options as key-value pairs
    array()  // attributes as key-value pairs
);
?>) 
but in 2.4.2 (source) doesn't have Aura folder or sql folder (that you use in your code)
and i wonder where do you type this code (what folder contain file which contain this code).
I have a code as above that i give you( I ran and it success) but i wonder
How do I use Aura frame work for that? and how i use aura.sql for my code?
Thank you very much




user.php

Hari K T

unread,
Mar 25, 2015, 11:53:58 AM3/25/15
to aur...@googlegroups.com
Hey,

First : The code you have shown are sql injection vulnerable . So I recommend not to do the same.

Please note : your code lies in E:/aurasql/ . 
 
next step i see you type (in Lazy Connection Instance
<?php
use Aura\Sql\ExtendedPdo;

$pdo = new ExtendedPdo(
    'mysql:host=localhost;dbname=test',
    'username',
    'password',
    array(), // driver options as key-value pairs
    array()  // attributes as key-value pairs
);
?>)  
but in 2.4.2 (source) doesn't have Aura folder or sql folder (that you use in your code)
May be I don't understand what you mean. The v1 is PSR-0 standard directory structure .


In v2 the folder structure is PSR-4 . That said don't worry about folder structure. 
and i wonder where do you type this code (what folder contain file which contain this code).
I don't know where the file with html you have shown ( first ) lies.

Let me belive it also lies at E:\aurasql\index.php .

You can add a line 

require __DIR__ . '/autoload.php';

Write the connection details below the file .

I have a code as above that i give you( I ran and it success) but i wonder

You are mixing up things :-) . Are you trying to use Aura.Sql inside the aura framework ?

If so the best way is to make use of composer ( http://getcomposer.org ) . Articles about composer and how to use are over sitepoint . Please do check.

I can demonstrate something quickly .

First I am creating the framework project

composer create-project aura/framework-project myproject

If you already have move to the same directory 

cd myproject

Install aura/sql 

composer require aura/sql

As you are new to DI I am skipping else it will be something like 

$di->params['Aura\Sql\ExtendedPdo'] = array(
    'dsn' => 'mysql:dbname=auraauth;host=127.0.0.1',
    'username' => 'root',
    'password' => 'mysqlroot'
);

for the current time use as in your controller 

use Aura\Sql\ExtendedPdo;

$pdo = new ExtendedPdo(
    'mysql:host=localhost;dbname=test',
    'username',
    'password',
    array(), // driver options as key-value pairs
    array()  // attributes as key-value pairs
);

Normally it should be in the config/Common.php .

How do I use Aura frame work for that? and how i use aura.sql for my code?

I know you will not get any details from the above and this will look very strange .

If you really like to learn you can look https://github.com/friendsofaura/Aura.Blog .

Browse through the source code and it may help you to some extend.

Hari K T

You can ring me : +91 9388 75 8821

Skype  : kthari85
Twitter : harikt
Reply all
Reply to author
Forward
0 new messages