# \[PHP\] Is sprintf() safe enough to rely on?

**URL:** <https://forum.kirupa.com/t/php-is-sprintf-safe-enough-to-rely-on/84454>\
**Category:** programming\
**Created:** [March 27, 2005, 9:38pm UTC](https://forum.kirupa.com/t/php-is-sprintf-safe-enough-to-rely-on/84454 "2005-03-27T21:38:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bluedackers](https://avatars.discourse-cdn.com/v4/letter/b/4bbf92/32.png) [@Bluedackers](https://forum.kirupa.com/u/Bluedackers)\
**Post date:** [March 27, 2005, 9:38pm UTC](https://forum.kirupa.com/t/php-is-sprintf-safe-enough-to-rely-on/84454/1 "2005-03-27T21:38:01Z")

</div>

Hello everyone!

After reading a lot of security-related articles on the net (and being blown away by everything that can go wrong), I’d like to know if the following would be a secure way to get information from a database:

```php
 function getInformation($id,$dbConnection){ 
 
if(is_int($id)){
$query = sprintf("SELECT * FROM table WHERE idcolumn = %d LIMIT 1",$id);
$result = mysql_query($query,$dbConnection);
$returnArray = mysql_fetch_array($result);
return $returnArray;
} else {
die("This script is protected against SQL injection.");
}
}

```

Does anyone here have any suggestions as far as security is concerned? (or any other comments are always welcome, of course)

Any thoughts would be greatly appreciated!

Kind regards,  
Maurits
